package com.api.syh56.shengyunhui.controller;

import com.api.syh56.shengyunhui.common.BaseUserInfo;
import com.api.syh56.shengyunhui.common.CommonPage;
import com.api.syh56.shengyunhui.common.CommonResult;
import com.api.syh56.shengyunhui.common.UserInfoEnu;
import com.api.syh56.shengyunhui.entity.Address;
import com.api.syh56.shengyunhui.entity.BankCard;
import com.api.syh56.shengyunhui.service.AddressService;
import com.api.syh56.shengyunhui.service.BankCardService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 银行卡
 */
@RestController
@RequestMapping("bankcard")
public class BankCardController {
    @Autowired
    private BankCardService bankCardService;

    /**
     * 插入
     * @param bankCard
     * @return
     */
    @PostMapping("insert")
    public CommonResult<Object> addNewAddress(@RequestBody BankCard bankCard){
//        address.setUid(Long.valueOf(BaseUserInfo.get(UserInfoEnu.id.getCode())));
        bankCardService.addNewBankCard(bankCard);
        return CommonResult.success(bankCard);
    }

    /**
     * 删除
     * @param bankCard
     * @return
     */
    @PostMapping("delete")
    public CommonResult<Object> delete(@RequestBody BankCard bankCard){
        bankCardService.removeBankCard(bankCard);
        return CommonResult.success(null);
    }


    /**
     * 分页查询
     * @param pageSize
     * @param pageNum
     * @return
     */
    @GetMapping(value = "selectPageByuid")
    public CommonResult<CommonPage<BankCard>>  selectPageByuid(@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                              @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        System.out.println(pageSize);
        System.out.println(pageNum);
        String id = BaseUserInfo.get(UserInfoEnu.id.getCode());
        Page<BankCard> addressPage = bankCardService.selectPageByuid(Long.valueOf(id),pageSize, pageNum);
        System.out.println(addressPage);

        return CommonResult.success(CommonPage.restPage(addressPage));
    }

}
